package net.godbirds.api.business;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import net.godbirds.Constant;
import net.godbirds.domain.mapper.TDefAppealMapper;
import net.godbirds.domain.model.TDefAppeal;
import net.godbirds.domain.model.TDefAppealExample;
import net.godbirds.domain.model.TDefUser;
@RestController
@RequestMapping("/business")
public class BusinessController {
	
	@Autowired
	TDefAppealMapper tDefAppealMapper;
	/**
	 * 申诉调解跳转
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/appUrl",method=RequestMethod.GET)
	public ModelAndView appUrl(HttpServletRequest request) {
		return new ModelAndView("business/AppealMediate");
	}
	/**
	 * 案件追踪跳转
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/trackUrl",method=RequestMethod.GET)
	public ModelAndView traceUrl(HttpServletRequest request) {
		return new ModelAndView("business/CaseFollow");
	}
	/**
	 * 案件追踪初始化
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/traceFollow",method=RequestMethod.GET)
	public Map<String,Object> traceFollow(HttpServletRequest request) {
		Map<String,Object> rtvMap = new HashMap<String,Object>();
		TDefUser tUser = (TDefUser)request.getSession().getAttribute(Constant.SESSION_USER_KEY);
		if(tUser == null) {
			rtvMap.put("msg", "长时间为操作，SESSION过期，请重新登录使用！");
			return rtvMap;
		}
		TDefAppealExample example = new TDefAppealExample();
		example.createCriteria().andOperatorEqualTo(tUser.getUserCode());
		List<TDefAppeal> tAppeals = tDefAppealMapper.selectByExample(example);
		if(tAppeals == null || tAppeals.size() <= 0) {
			rtvMap.put("msg", "您当前无案件");
			rtvMap.put("error", "1");
			return rtvMap;
		}
		rtvMap.put("appeals", tAppeals);
		return rtvMap;
	}
	
}
